<script setup lang="ts">
import PureTableBar from "@/components/RePureTableBar/src/bar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { Plus, EditPen, Delete } from "@element-plus/icons-vue";
import useRtcmGroupHooks from "@/views/rtcmGroup/utils/hook";

const {
  rtcmGroupForm,
  loading,
  rtcmGroupList,
  getRtcmGroup,
  reset,
  deleteGroup,
  columns,
  addRtcmGroup,
  rtcmGroupParams,
  updateRtcmGroup
} = useRtcmGroupHooks();
</script>

<template>
  <div class="main">
    <el-form
      :inline="true"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
    >
      <el-row :gutter="20" :justify="'space-around'">
        <el-col :span="12">
          <el-form-item label="分组名称:">
            <el-input
              v-model="rtcmGroupForm.name"
              placeholder="请输入分组名称"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getRtcmGroup">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="组名:">
            <el-input
              v-model="rtcmGroupParams.groupName"
              placeholder="请输入组名"
              clearable
            />
          </el-form-item>

          <el-form-item>
            <el-tooltip placement="top" content="请输入组名再点击新增分组">
              <el-button
                type="primary"
                :disabled="
                  ['', null, undefined].includes(rtcmGroupParams.groupName)
                "
                :icon="useRenderIcon(Plus)"
                @click="addRtcmGroup"
              >
                新增分组
              </el-button>
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <PureTableBar title="分组列表" :columns="columns" @refresh="getRtcmGroup">
      <template v-slot="{ size, dynamicColumns }">
        <pure-table
          highlight-current-row
          border
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          :size="size"
          adaptive
          :data="rtcmGroupList"
          :columns="dynamicColumns"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }"
        >
          <template #operation="{ row }">
            <el-button
              class="reset-margin"
              link
              type="primary"
              :size="size"
              :icon="useRenderIcon(EditPen)"
              @click="updateRtcmGroup(row)"
            >
              {{ row.flag ? "确定" : "修改" }}
            </el-button>
            <el-popconfirm
              :title="`是否确认删除'${row.groupName}'分组`"
              @confirm="deleteGroup(row.id)"
            >
              <template #reference>
                <el-button
                  class="reset-margin"
                  link
                  type="danger"
                  :size="size"
                  :icon="useRenderIcon(Delete)"
                >
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss"></style>
